package com.lyt.controller;

import com.lyt.service.PaperService;
import com.lyt.vo.PaperVo;
import com.lyt.vo.QuestionVo;
import com.lyt.vo.QuestionsVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: zjx
 * @Date: 2023/04/27/20:03
 * @Description:
 */
@RestController
@CrossOrigin
public class PaperController {

    //添加试卷，lyt
    @Autowired
    PaperService paperService;
    @RequestMapping("/edit/paper")
    public String addQuestion(@RequestBody PaperVo paperVo ){

        paperService.addPaper(paperVo);
        return "okkkk";
    }

    //自动添加试卷，zjx
    @RequestMapping("/addPaperAut")
    public String addPaperAut(@RequestBody PaperVo paperVo ){
        int i = paperService.addPaperAut(paperVo);
        if (i == 2){
            return  "选择题数量不足";
        }else if (i == 3){
            return  "判断题数量不足";
        }else if (i == 4){
            return  "问答题数量不足";
        }
        return "创建成功";
    }

    //根据试卷编号获取试卷，lyt
    @RequestMapping("/get/paper")
    public PaperVo getPaper(@Param("id") Integer id){
        System.out.println("---------------------"+id);
        PaperVo paperVo = paperService.getPaperById(id);
        return paperVo;
    }

    //根据试卷编号删除试卷，zjx
    @RequestMapping("/paper/delete/{id}")
    public int deletePaper(@PathVariable("id") Integer id){
        return paperService.deletePaper(id);
    }

    //根据年级查询所有试卷，zjx
    @RequestMapping("/paper/grade")
    public List<PaperVo> getAllByGradePaper(@Param("grade") Integer grade){
        return paperService.getAllByGradePaper(grade);
    }

    //查询所有试卷，zjx
    @RequestMapping("/paper/get")
    public List<PaperVo> getAllPaper(){
        return paperService.getAllPaper();
    }

    //根据试卷编号删除试卷，zjx
    @RequestMapping("/paper/courseId")
    public List<PaperVo> getAllByCoursePaper(@Param("courseId") Integer courseId){
        return paperService.getAllByCoursePaper(courseId);
    }

    //发布试卷，zjx
    @RequestMapping("/commit/paper")
    public String commitPaper(@Param("paperId")Integer paperId){
        paperService.commitPaper(1,paperId);
        return "okkkk";
    }
}
